﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Captcha
{
    public class Program
    {
        //参考一起帮的登录页面，绘制一个验证码图片，存放到当前项目中。验证码应包含：
        //1.随机字符串
        //2.混淆用的各色像素点
        //3.混淆用的直线（或曲线）
        //白色底 生成四位随机字母数字 生成随机像素点 生成随机灰色线
     
        static void Main(string[] args)
        {
            ConstructDb();

            SqlDbContext context = new SqlDbContext();

            context.Teachers.Where(t => t.Id > 3)
                .Include(t => t.Students
                .Select(s => s.SleepIn))
                .Include(t => t.Students
                .Select(s => s.StudyIn))
                .FirstOrDefault();


            //查找关联的实体表中的信息 context.Set会直接在目标Bed表中查找，不用通过Student去查询
            context.Students.Where(s => s.SleepIn.Location == " ").FirstOrDefault();
            context.Set<Bed>().Where(b => b.Location == " ").FirstOrDefault();

            ////插入数据
            //Student lgy = new Student
            //{
            //    Id = Guid.NewGuid(),
            //    Name = "lgy",
            //    SleepIn = new Bed()

            //};
            //context.Students.Add(lgy);

            //Teacher fg = new Teacher { Id = Guid.NewGuid(), Name = "fg" };
            //context.Teachers.Add(fg);

            //context.SaveChanges();

            //查找数据
            //Person fg = context.Teachers.Where(p => p.Name == "fg").FirstOrDefault();
            //Console.WriteLine(fg.Id);

            //string query = "SELECT * FROM Students WHERE Id = @p0";
            //DbSqlQuery<Student> sqlQuery = context.Students.SqlQuery(query, 1);
            //Console.WriteLine(sqlQuery);



            #region MyRegion

            ////public static Color FromArgb(int alpha, int red, int green, int blue);
            //Bitmap image = new Bitmap(250, 100);  //生成一个像素图“画板”
            //Graphics g = Graphics.FromImage(image);    //在画板的基础上生成一个绘图对象
            //g.Clear(Color.White);           //添加底色

            //string[] word = new string[] { "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm0123456789" };
            //Random random = new Random();
            //for (int i = 0; i < 4; i++)
            //{
            //    //string w = random.Next(0,word.Length)


            //}

            //g.DrawLine(new Pen(Color.Gray), new Point(0, 0), new Point(100, 50)); //画直线
            //g.DrawString("hello, luckystack",       //绘制字符串
            //    new Font("宋体", 14),                //指定字体
            //    new SolidBrush(Color.DarkRed),      //绘制时使用的刷子
            //    new PointF(5, 6)                    //左上角定位
            //);

            //image.SetPixel(195, 95, Color.BlueViolet);  //绘制一个像素的点

            //image.Save(@"C:\17bang\hello.jpg", ImageFormat.Jpeg);   //保存到文件
            #endregion
        }
        static void ConstructDb()
        {
            //EF6自动创建数据库和表，不用连接数据库
            SqlDbContext context = new SqlDbContext();
            //Database db = context.Database;
            context.Database.Delete();
            context.Database.Create();
        }
    }
}
